package com.groupbuying.cheetah.order.agentMoneyFlow;

import com.groupbuying.cheetah.common.PageUtils;
import com.groupbuying.cheetah.common.Query;
import com.groupbuying.cheetah.domain.CheetahOrderStoremoneyflowDO;
import com.groupbuying.cheetah.domain.CheetahTmpOrderFlowDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/* 够样优店管理后台---财务管理---代理商流水管理 */
@RestController
@RequestMapping("/agentMoneyFlow")
public class AgentMoneyFlowController {
  private static final Logger logger = LoggerFactory.getLogger(AgentMoneyFlowController.class);

  @Autowired
  private AgentMoneyFlowDAO agentMoneyFlowDAO;

  @GetMapping("/list")
  public PageUtils list(@RequestParam Map<String, Object> params) {

    Query query = new Query(params);
    logger.error("SysAgentInfoServiceImpl.list()-->从agent接受的参数信息:"+ params.toString());
    List<CheetahTmpOrderFlowDO> storeMoneyFlowList = agentMoneyFlowDAO.list(query);
    for (CheetahTmpOrderFlowDO cheetahTmpOrderFlowDO : storeMoneyFlowList) {
      String dateStr=dateToStrLong(cheetahTmpOrderFlowDO.getOrderPayTimeDate());
      cheetahTmpOrderFlowDO.setOrderPayTime(dateStr);
    }
    int total = agentMoneyFlowDAO.count(params);
    PageUtils pageUtils = new PageUtils(storeMoneyFlowList, total);
    logger.error("SysAgentInfoServiceImpl.list()-->从pageUtils返回信息为:"+ pageUtils.getRows());
    logger.error("SysAgentInfoServiceImpl.list()-->从pageUtils返回信息为:"+ pageUtils.getTotal());
    return pageUtils;

  }


  @GetMapping("/export")
  public void refundManagement(@RequestParam Map<String, Object> params, HttpServletResponse response) {


    Query query = new Query(params);
    List<Map<String, String>> storeMoneyFlowList = agentMoneyFlowDAO.listAgentMoneyFlow(query);
    try {
     // String[] header = { "订单编号", "买家名称","门店名称", "运营专员","下单时间","现金支付", "零钱支付","订单总金额", "支付方式","订单类型","支付状态"};
      //Object[] columns = { "orderId", "customerId","storeName","operationSpecialist","orderTime","cashPayment","small_change","grossAmount","payType","order_type","order_state"};
      //ExcelUtils.writeExcelByObject(storeMoneyFlowList, response, "商户流水账单", header, columns);
    } catch (Exception e) {
      e.printStackTrace();

    }
  }
  public static String dateToStrLong(java.util.Date dateDate) {
     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String dateString = formatter.format(dateDate);
      return dateString;
    }

}
